﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Member;
using WuDada.Core.Member.Service;
using WuDada.Core.Member.Domain;

public partial class UserControl_Login : System.Web.UI.UserControl
{
    private MemberFactory m_MemberFactory;
    private IMemberService m_MemberService;
    private SessionHelper m_SessionHelper;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_MemberFactory = new MemberFactory();
        m_MemberService = m_MemberFactory.GetMemberService();
        m_SessionHelper = new SessionHelper();

        if (!IsPostBack)
        {
            if (m_SessionHelper.Member != null)
            {
                pnlLogout.Visible = true;
                pnlLogin.Visible = false;
                ltlName.Text = m_SessionHelper.Member.Name;
            }
            else
            {
                pnlLogout.Visible = false;
                pnlLogin.Visible = true;
            }
        }
    }

    //protected void btnLogin_Click(object sender, EventArgs e)
    //{
    //    MemberVO memberVO = m_MemberService.GetMemberByLoginId(txtLoginId.Text.Trim());

    //    if (memberVO != null && memberVO.Password.Equals(txtPassword.Text.Trim()))
    //    {
    //        if (!memberVO.Status.Equals("1"))
    //        {
    //            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("登入失敗，帳號停權中"), false);
    //            return;
    //        }
    //        else
    //        {
    //            m_SessionHelper.Member = memberVO;                
    //            Response.Redirect(Request.Url.ToString());
    //            return;
    //        }
    //    }

    //    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("登入失敗，帳號或密碼錯誤"), false);
    //}

    protected void btnLogout_Click(object sender, EventArgs e)
    {
        m_SessionHelper.Member = null;
        Response.Redirect(Request.Url.ToString());
    }
}